<template>
	<view class="reportStyle">
		<view class="topSearch">
			<u-search placeholder="请输入物资类型" v-model="keyword" @blur="onBlurSearch" @clear="onClearBtnOK" :animation="false" :showAction="false"></u-search>
		</view>
		<!-- <view class="dropdown_top">
			<zb-dropdown-menu style="width: 33.33%">
				<zb-dropdown-item name="类型" :options="option" v-model="fication" @change="ficationChange"></zb-dropdown-item>
			</zb-dropdown-menu>
			<zb-dropdown-menu style="width: 33.33%">
				<zb-dropdown-item name="全部" :options="option" v-model="fication" @change="ficationChange"></zb-dropdown-item>
			</zb-dropdown-menu>
			<zb-dropdown-menu style="width: 33.33%">
				<zb-dropdown-item name="全部" :options="option" v-model="fication" @change="ficationChange"></zb-dropdown-item>
			</zb-dropdown-menu>
		</view> -->
		<view class="uni-container">
			<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<uni-th width="50" align="center">物资编号</uni-th>
					<uni-th width="50" align="center">物资名称</uni-th>
					<uni-th width="50" align="center">物资类型</uni-th>
					<uni-th width="50" align="center">当前库存</uni-th>
					<uni-th width="50" align="center">计量单位</uni-th>
					<uni-th width="50" align="center">安全库存</uni-th>
					<uni-th width="50" align="center">物资规格</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td>{{ index }}</uni-td>
					<uni-td>{{ item.goodsKind_dictText }}</uni-td>
					<uni-td>{{ item.goodsName }}</uni-td>
					<uni-td>{{ item.allStock }}</uni-td>
					<uni-td>{{ item.meterUnit_dictText }}</uni-td>
					<uni-td>{{ item.stockpileMin }}</uni-td>
					<uni-td>{{ item.goodsNorms }}</uni-td>
				</uni-tr>
			</uni-table>
			<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="change" /></view>
		</view>
	</view>
</template>

<script>
import tableData from './tableData.js';
import { getStoreRelev } from '@/api/mappages/materials/materials.js';

export default {
	data() {
		return {
			optionsData: '',
			keyword: '',
			fication: 4, //整改状态
			option: [
				{
					text: '交办中',
					value: 0
				},
				{
					text: '已登记',
					value: 1
				},
				{
					text: '已整改',
					value: 2
				},
				{
					text: '已退回',
					value: 3
				},
				{
					text: '整改状态',
					value: 4
				}
			],
			searchVal: '',
			tableData: [],
			// 每页数据量
			pageSize: 6,
			// 当前页
			pageCurrent: 1,
			// 数据总量
			total: 0,
			loading: false
		};
	},
	onLoad(options) {
		this.selectedIndexs = [];
		if (options.item) {
			this.optionsData = JSON.parse(decodeURIComponent(options.item));
			console.log(this.optionsData, '2221111111'); // 现在可以使用传递的 item 数据
		}
		this.getData(1);
	},
	methods: {
		onBlurSearch() {
			this.request();
		},
		onClearBtnOK() {
			this.request();
		},
		//整改状态
		ficationChange() {
			// this.patrolShow = true;
		},

		// 分页触发
		change(e) {
			this.$refs.table.clearSelection();
			this.selectedIndexs.length = 0;
			this.getData(e.current);
		},
		// 搜索
		search() {
			this.getData(1, this.searchVal);
		},
		// 获取数据
		getData(pageCurrent, value = '') {
			this.loading = true;
			this.pageCurrent = pageCurrent;
			this.request({
				pageSize: this.pageSize,
				pageCurrent: pageCurrent,
				value: value,
				success: (res) => {
					// console.log('data', res);
					this.tableData = res.data;
					this.total = res.total;
					this.loading = false;
				}
			});
		},
		// 伪request请求
		async request(options) {
			let brr = {
				size: 99999,
				goodsName: this.keyword,
				storeName:this.optionsData
			};
			let arr = await getStoreRelev(brr);
			let res = arr.result.records;
			const { pageSize, pageCurrent, success, value } = options;
			let total = res.length;
			let data = res.filter((item, index) => {
				const idx = index - (pageCurrent - 1) * pageSize;
				return idx < pageSize && idx >= 0;
			});
			if (value) {
				data = [];
				res.forEach((item) => {
					if (item.name.indexOf(value) !== -1) {
						data.push(item);
					}
				});
				total = data.length;
			}

			setTimeout(() => {
				typeof success === 'function' &&
					success({
						data: data,
						total: total
					});
			}, 500);
		}
	}
};
</script>

<style scoped lang="scss">
.reportStyle {
	height: calc(100vh - 88rpx);
	background-color: #fff !important;
}
.topSearch {
	padding: 10rpx;
}
.dropdown_top {
	display: flex;
	flex-direction: row;
}

.uni-group {
	display: flex;
	align-items: center;
}
.uni-table-th {
	background: rgba(227, 238, 255, 0.8);
	color: #4988d5;
}
</style>
